package com.crealth.memcached;

import java.util.List;

import com.crealth.db.ConsumerDb;
import com.crealth.model.ConsumerLoanModel;


public class ConsumerLoanCached {
	private static final String loanKeyPrefix = "loan_csmid_";
	
	@SuppressWarnings("unchecked")
	public static List<ConsumerLoanModel> selectConsumerLoan(int consumerID) {
		String key = loanKeyPrefix + consumerID;
		Object obj = MemcachedMgr.cachedClient.get(key);
		List<ConsumerLoanModel> loanls = null;
		if (obj != null) {
			loanls = (List<ConsumerLoanModel>)obj;
		}
		else {
			loanls = ConsumerDb.selectConsumerLoan(consumerID);
			if (loanls != null) {
				MemcachedMgr.cachedClient.set(key, loanls);
			}
		}
		
		return loanls;
	}
	
	public static void deleteCached(int consumerID) {
		String key = loanKeyPrefix + consumerID;
		MemcachedMgr.cachedClient.delete(key);
	}
	
}
